<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑项目信息</title>
    <link href="../css/creat-pro.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<!--header-->
<header id="header" class="header">
    <div class="header-info left"><i></i><a href="javascript:" onclick="toProDetail()">项目信息</a> > 编辑项目信息</div>
    <div class="right-user right">
         <div class="clear t" >             <div id="headusername" class="role"></div>             <div class="icon"></div>         </div>
        <div class="head-down">
            <ul><li><a hre f="edit-pwd.html">修改密码</a></li><li><a onclick="loginOut()">退出系统</a></li></ul></div><div>
    </div>
    </div>
</header>
<!--menu-->
<aside id="aside" class="aside">
    <div class="logo">运营平台</div>
    <ul class="menu" id="asidemenu">
    </ul>
</aside>


<!--content-->
<div class="content">
    <div class="creat-pro">
        <div class="pro-head"><i></i>编辑项目信息</div>


        <table class="pro-table">
            <thead>
                <tr>
                    <th width="100">基本信息</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><span class="red-start">*</span>医院全称</td>
                    <td><input type="" name="" id="name" ></td>
                </tr>
                <tr>
                    <td>简称</td>
                    <td><input type="" name="" id="shortName"></td>
                </tr>
                <tr>
                    <td>别称</td>
                    <td><input type="" name="" id="alias"><span style="color: #009926;padding: 0 0 0 5px">多个别称，用英文","隔开</span></td>
                </tr>
                <tr>
                    <td><span class="red-start">*</span>Segmentation</td>
                    <td><select id="segmentation"></select></td>
                </tr>
                <tr>
                    <td><span class="red-start">*</span>级别</td>
                    <td><select id="level"></select></td>
                </tr>

                <tr>
                    <td><span class="red-start">*</span>有无高铁</td>
                    <td><label><input type="radio" value="1" name="hsrEnable">&nbsp;有</label>&emsp;<label><input type="radio" name="hsrEnable" value="0">&nbsp;无</label></td>
                </tr>
                <tr>
                    <td width="150"><span class="red-start">*</span>是否为百强医院</td>
                    <td><label><input type="radio" value="1" name="isTopHundred">&nbsp;是</label>&emsp;<label><input type="radio" name="isTopHundred" checked="checked" value="0">&nbsp;否</label></td>
                </tr>
                <!--<tr>-->
                    <!--<td>邮编</td>-->
                    <!--<td><input type="" name="" class="short" id="postcode"></td>-->
                <!--</tr>-->
                <tr>
                    <td>床位</td>
                    <td>
                        <div class="clearfix number">
                        <a href="javascript:;" class="left sub" onclick="subNum()">-</a>
                        <input onblur="this.value=(this.value+'').replace(/\D/g,'');" class="left" value="1" id="bed">
                        <a class="left add" onclick="addNum()">+</a>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>年诊疗人次</td>
                    <td><input type="" name="" class="short" id="people"></td>
                </tr>
                
            </tbody>
            <thead>
                <tr>
                    <th width="100">地址信息</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><span class="red-start">*</span>所属区域</td>
                    <td><select id="district" onchange="$(this).removeClass('error-i')"><option>请选择</option></select>&emsp;<select onchange="$(this).removeClass('error-i')" id="province"><option>请选择</option></select>&emsp;<select onchange="$(this).removeClass('error-i')" id="city"><option>请选择</option></select></td>
                </tr>
                <tr>
                    <td><span class="red-start">*</span>地址</td>
                    <td><input type="" name="" class="short" id="address"></td>
                </tr>
                <tr>
                    <td>设备科位置</td>
                    <td><input type="" name="" class="short" id="location"></td>
                </tr>
                <!--<tr>-->
                    <!--<td>维度</td>-->
                    <!--<td><input type="" name="" class="short" id="latitude"></td>-->
                <!--</tr>-->
                <!--<tr>-->
                    <!--<td>经度</td>-->
                    <!--<td><input type="" name="" class="short" id="longitude"></td>-->
                <!--</tr>-->
            </tbody>
            <tbody>
                <tr>
                    <td></td>
                    <td><a class="pro-btn" onclick="cancelEdit()">取消</a>&emsp;<a class="pro-btn pro-sure pro-sure-can" onclick="creatItem()">提交</a></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<script src='../js/jquery.min.js'  type="text/javascript"></script>
<script src="../js/jquery.cookie.js"></script>
<script src="../js/common.js"></script>

<script type="text/javascript">
    function toProDetail() {
        location.href = 'mems-pro-baseInfo.html?id='+getUrlId()+'&name='+$$.getUrlParaObj()['name'];
    }
    function cancelEdit() {
        location.href = 'mems-pro-baseInfo.html?id=' + getUrlId()+'&name='+$$.getUrlParaObj()['name'];
    }

    _API.dynamicDistrick('district','province','city');

    //权限控制
    var roleid = $.cookie('userrole');
    if(roleid == 1 || roleid == 2 || roleid == 0){
        $('#name').prop({'disabled':'disabled'});
        $('#segmentation').prop({'disabled':true})
        $('#level').prop({'disabled':true});
        $('input[name=isTopHundred]').prop({'disabled':'disabled'})
    }
//    if(roleid==9 || roleid==3){
//        $('#isTopHundredTr').css({'visibility':'visible'});
//    }



    getItem()
    function getItem() {

        var url = _ip + '/project/select?id=' + getUrlId();
        var data = {}

        $.ajax({
            url: url,
            type: 'GET',
            dataType: 'jsonp',
            async: false,
            contentType: 'application/json',
            jsonpCallback: 'info',
            success: function (data) {
                if (data.message === 'LOGIN') {
                    location.href = 'user-login.html';
                    return false;
                }

                if (data.success) {
                    var data = data.data;
                    $('#name').val(data.name);
                    $('#shortName').val(data.shortName);
                    $('#alias').val(data.alias);
                    $('#segmentation').val(data.segmentation);
                    $('#level').val(data.level);
                    if(data.hsrEnable == 1){
                        $("input[name='hsrEnable'][value='1']").prop('checked',true);
                    }else{
                        $("input[name='hsrEnable'][value='0']").prop('checked',true);
                    }
                    if(data.isTopHundred == 1){
                        $("input[name='isTopHundred'][value='1']").prop('checked',true);
                    }else{
                        $("input[name='isTopHundred'][value='0']").prop('checked',true);
                    }
//                    $('#hsrEnable').html((data.hsrEnable == 1 ? '有' : '无'));
                    $('#postcode').val(data.postcode);
                    $('#bed').val(data.bed?data.bed:0);
                    $('#people').val(data.people);
                    _API.getPLevelList('level',data.level,false)
                        .getPSegmentationList('segmentation',data.segmentation,false)
                        .getDistrict('district',data.area,true)
                        .getPrivence('province',data.province,true,data.area)
                        .getCity('city',data.city,true,data.area,data.province);
                    $('#address').val(data.address);
                    $('#location').val(data.location);
                    $('#latitude').val(data.latitude);
                    $('#longitude').val(data.longitude);

                }
            }
        })
    }



    function addNum() {
        var input = $('#bed');
        var val = parseInt(input.val());
        var newVal = val + 1;
        input.val(newVal );
    }
    function subNum() {
        var input = $('#bed');
        var val = parseInt(input.val());
        var newVal = val - 1;
        if(newVal <= 1){
            newVal = 1;
        }
        input.val( newVal );
    }


    var arr = ['name','address'];
    for(var k = 0; k < 2; k ++){
        $('#'+arr[k]).focus(function(){
            $(this).removeClass('error-i');
        })
    }

    var isClick = false;
    function creatItem() {

        var flag = true;
        for(var k = 0; k < 2; k ++){
            var v = $('#'+arr[k]).val();
            if(v == ""){
               $('#'+arr[k]).addClass('error-i');
                flag = false;
               break;
            }
        }
        var district = $('#district').find('option:selected').text();
        var province = $('#province').find('option:selected').text();
        var city = $('#city').find('option:selected').text();
        if(district == '请选择'){
            $('#district').addClass('error-i');
            return false;
        }
        if(province == '请选择'){
            $('#province').addClass('error-i');
            return false
        }
        if(city == '请选择'){
            $('#city').addClass('error-i');
            return false;
        }

        if(!flag) return;
        var url  = _ip+'/project/update';
        var data = {
            "id":parseInt(getUrlId()),
            "name": $('#name').val() || null,
            "shortName":$('#shortName').val() || null,
            "alias":$('#alias').val() || null,
            "segmentation": $('#segmentation').val() || null,
            "level": $('#level').val() || null,
            "hsrEnable":parseInt($('input[name=hsrEnable]:checked').val()) ,
            "isTopHundred":parseInt($('input[name=isTopHundred]:checked').val()) || null,
            "bed":parseInt($('#bed').val())  || null,
            "people":parseInt($('#people').val()) || null,
            "province": $('#province').val() || null,
            "city": $('#city').val() || null,
            "area": $('#district').val() || null,
            "address":$('#address').val() || null,
            "location":$('#location').val() || null,
            "creater": $.cookie('userid')
        }
        if(isClick) return;
        $('.pro-sure-can').addClass('sending');
        isClick = true;
        $.ajax({
            url:url,
            type : "POST",
            xhrFields: {
               withCredentials: true
            },
            crossDomain: true,
            dataType: 'json',
            contentType:'application/json',
            data:JSON.stringify(data),
            success:function(data){
                if(data.message === 'LOGIN') {
                    location.href = 'user-login.html';
                    return false;
                }
                if(data.success){
                    location.href = 'mems-pro-baseInfo.html?id='+getUrlId();
                }else{
                    $(that).removeCla
                    isClick = false;
                    if(data.message == '项目名重复，请重新输入'){
                        $('#name').addClass('error-i')

                    }
                    alert(data.message);
                }
            }
        })
   }
</script>
</body>
</html>